﻿using System.Collections.Generic;
using System.Linq;
using Ecos.GroceryList.Domain;
using Ecos.GroceryList.Host;

namespace Ecos.GroceryList.AppService
{
    public class GroceryListService : IGroceryListService
    {
        private readonly Domain.GroceryList _activeList;

        protected IGroceryListRepository GroceryLists { get; set; }

        public GroceryListService()
        {
            GroceryLists = new GroceryListRepository();
            _activeList = GroceryLists.Query();
        }

        public void Add(string newItem)
        {
            var product = Product.From(newItem);
            _activeList.Add(product);
        }

        public IEnumerable<string> QueryList()
        {
            return _activeList.ReturnAllProducts().Select(p=>p.ToString());
        }
    }
}
